import { createSlice } from "@reduxjs/toolkit";
import axios from "axios";
//解决异步的
const channelStore = createSlice({
    name: 'channell',
    initialState: {
        channelList: [],
    },
    reducers: {
        setChannels(state, action) {
            state.channelList = action.payload
        }
    }
})

//异步请求部分
const { setChannels } = channelStore.actions

const fetchChannlList = () => {
    return async (dispatch) => {
        const res = await axios.get('http://localhost:3001/msg')
        dispatch(setChannels(res.data.data.setChannels))
    }
}

export { fetchChannlList }
const reducer = channelStore.reducer
export default reducer